package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbBrandExample;
import com.dongdongshop.service.TbBrandServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Stream;

@Service//交给spring容器 Component也可以代替
@Component
public class TbBrandServiceImpl implements TbBrandServiceI {

    @Autowired
    private TbBrandMapper tbBrandMapper;
    @Override
    public List<TbBrand> getFindAll() {
        return tbBrandMapper.selectByExample(new TbBrandExample());
    }

    @Override
    public TbBrand selectTbBrandById(Integer id) {
        return tbBrandMapper.selectByPrimaryKey(id.longValue());
    }

    @Override
    @Transactional //事物
    public void updateTbBrand(TbBrand tbBrand) {
        tbBrandMapper.updateByPrimaryKeySelective(tbBrand);
    }

    @Override
    @Transactional //事物
    public void addTbBrand(TbBrand tbBrand) {
        tbBrandMapper.insertSelective(tbBrand);
    }

    @Override
    @Transactional //事物
    public void deleteTbBrand(List<Integer> list) {
        Stream<Integer> stream = list.stream();
        Consumer<Integer> consumer = id -> tbBrandMapper.deleteByPrimaryKey(id.longValue());
        stream.forEach(consumer);
    }
}
